{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b5871cc4-b9f4-4faf-a500-36c6df560d72",
   "metadata": {},
   "source": [
    "# 基础操作"
   ]
  },
  {
   "cell_type": "raw",
   "id": "92630a5f-05ff-41cc-8ff5-d9c3c6e769ad",
   "metadata": {},
   "source": [
    "键盘操作：\n",
    "A 上加一行\n",
    "B 下加一行\n",
    "DD 删除\n",
    "Ctrl+M：M强R弱Y恢复"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ee4e05d2-46d2-46de-b81e-1c5747f16c25",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n"
     ]
    }
   ],
   "source": [
    "x = 1\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0b81e8a2-4853-4cb7-9f6b-c56158610f11",
   "metadata": {},
   "source": [
    "三个重要属性"
   ]
  },
  {
   "cell_type": "raw",
   "id": "39cc01f7-2824-47aa-9e81-36bd172f9050",
   "metadata": {},
   "source": [
    "dtype = data type\n",
    "\n",
    "    float,uint8,float32\n",
    "\n",
    "shape\n",
    "\n",
    "ndim"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "678b2c41-211e-4c05-ab26-3d1dfdf23f62",
   "metadata": {},
   "source": [
    "## 矩阵创建"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "344165f4-470a-4d1f-b0de-5beb1fbee3bf",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy\n",
    "import cv2\n",
    "import matplotlib\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "b2e303b8-66e7-4cb5-a386-55c6a8be27c8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 3])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = np.array([1,2,3])\n",
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "254f5d1f-d9fc-4017-b97c-bdc8f03e4f90",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 1, 1], dtype=uint8)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y = np.uint8([1,1,1])\n",
    "y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "fd7c0cb3-a270-4953-b9b4-d968460fa7d8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dtype('int32')"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x.dtype"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "cbe4c95a-e9da-459d-b8ef-572a5db43b7e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1., 2., 3.], dtype=float32)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.float32(x)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d1cfbd41-756e-49a0-b660-8462df57b7bf",
   "metadata": {},
   "source": [
    "## arange"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "42b8657b-1e09-418a-bf17-97d4f712bfd6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.arange(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "0e604299-b413-4bf7-b5b7-2714dcde882e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2, 3, 4, 5, 6, 7, 8, 9])"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.arange(2,10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "32529f6f-8cd5-4626-bdae-68f594a9f95b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2. , 3.5, 5. , 6.5, 8. , 9.5])"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.arange(2,10,1.5)"
   ]
  },
  {
   "cell_type": "raw",
   "id": "eacca917-e337-49ea-9ab2-81d85efa9df7",
   "metadata": {},
   "source": [
    "shift+tab描述信息"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "738a352e-365a-45e7-8b37-39bb03fa2da6",
   "metadata": {},
   "source": [
    "## linspace"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "5ff57299-6e51-4d3f-a553-0c5e4af9cd9c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 1.        ,  1.18367347,  1.36734694,  1.55102041,  1.73469388,\n",
       "        1.91836735,  2.10204082,  2.28571429,  2.46938776,  2.65306122,\n",
       "        2.83673469,  3.02040816,  3.20408163,  3.3877551 ,  3.57142857,\n",
       "        3.75510204,  3.93877551,  4.12244898,  4.30612245,  4.48979592,\n",
       "        4.67346939,  4.85714286,  5.04081633,  5.2244898 ,  5.40816327,\n",
       "        5.59183673,  5.7755102 ,  5.95918367,  6.14285714,  6.32653061,\n",
       "        6.51020408,  6.69387755,  6.87755102,  7.06122449,  7.24489796,\n",
       "        7.42857143,  7.6122449 ,  7.79591837,  7.97959184,  8.16326531,\n",
       "        8.34693878,  8.53061224,  8.71428571,  8.89795918,  9.08163265,\n",
       "        9.26530612,  9.44897959,  9.63265306,  9.81632653, 10.        ])"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.linspace(1,10)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "44b5d876-e89f-426f-85e2-b3dfce1f151c",
   "metadata": {},
   "source": [
    "## zeros"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "a6e7bf6e-5119-4699-80a8-e5eb790cef7c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0., 0., 0., 0.],\n",
       "       [0., 0., 0., 0.]])"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.zeros((2,4))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2be0aead-baa7-4b6d-abd2-282c20408956",
   "metadata": {},
   "source": [
    "## eye"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "b1e66ee3-3701-4a99-9b26-b6f09f868822",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 0., 0.],\n",
       "       [0., 1., 0.],\n",
       "       [0., 0., 1.]])"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.eye(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "3383eaa0-fa1f-4a94-97eb-f09bc2a24f4e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 0., 0.],\n",
       "       [0., 1., 0.],\n",
       "       [0., 0., 1.]])"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.identity(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d3b264d1-bdbd-409b-b7d9-1fc206abaa27",
   "metadata": {},
   "source": [
    "## random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "f25e8907-4406-4619-a596-31205cb1ef88",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[66, 58, 97, 61, 56, 76, 40, 80, 40,  1],\n",
       "       [79, 33, 54, 49, 31, 91, 59,  2, 60, 11],\n",
       "       [27, 14, 33, 40, 14, 40, 19, 75,  9, 36],\n",
       "       [37, 18, 56, 32, 49, 67, 87, 92, 65, 84],\n",
       "       [93, 46, 54, 30, 11, 88, 26,  1, 57, 45],\n",
       "       [81, 65, 82, 19, 98,  6, 33, 98, 42, 68],\n",
       "       [22,  7, 69, 53, 64, 84, 73,  1, 76, 30],\n",
       "       [68, 53,  0, 92, 35, 75, 69, 99, 88, 26],\n",
       "       [49, 95, 42, 96, 58, 53, 27, 94,  3, 56],\n",
       "       [20, 21, 36, 70,  7,  1, 21, 63, 83, 11]])"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.randint(0,100,(10,10))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e5ed456f-ca61-4527-b0d0-0eee9845c5d1",
   "metadata": {},
   "source": [
    "# 矩阵"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "675c15f4-3f9a-47e6-bbf9-d161cba4585c",
   "metadata": {},
   "source": [
    "## 矩阵转换"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "5779d5ce-4f0e-4ebe-94ea-554e78a931c2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 1, 1],\n",
       "       [1, 1, 1],\n",
       "       [1, 1, 1]], dtype=uint8)"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#创建矩阵\n",
    "A = np.ones((3,3),dtype=np.uint8)\n",
    "A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "5770f810-35b8-4bca-97b9-c036e3a76112",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 1, 1, 1, 1, 1, 1, 1, 1]], dtype=uint8)"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#方法\n",
    "A.reshape((-1,9))#-1自动计算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "8ba8e79e-0ed8-4ac3-b127-81db3ff6e92b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 1, 1, 1, 1, 1, 1, 1, 1], dtype=uint8)"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#复制\n",
    "A.flatten()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "6cc82591-56c6-40b7-9c27-70941dfc3ff3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 1, 1, 1, 1, 1, 1, 1, 1], dtype=uint8)"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#引用\n",
    "A.ravel()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "90543cd5-3f83-48a4-919a-1074f437ca9b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 1, 1],\n",
       "       [1, 1, 1],\n",
       "       [1, 1, 1]], dtype=uint8)"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#转置\n",
    "A.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "a11020da-6786-42fc-82ff-4f594d8a119b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 1, 1],\n",
       "       [1, 1, 1],\n",
       "       [1, 1, 1]], dtype=uint8)"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#转置\n",
    "A.transpose()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "9e76a20e-f1a4-45bc-953b-670039b98370",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 0, 7],\n",
       "       [7, 2, 8],\n",
       "       [6, 7, 1]])"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "B = np.random.randint(0,10,(3,3))\n",
    "B"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "29700fda-3831-48f6-8860-26d944a1a470",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 7, 6],\n",
       "       [0, 2, 7],\n",
       "       [7, 8, 1]])"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "B.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "c2e4b583-6002-4992-aacb-cba1d4608a91",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 1, 1, 0, 0, 7],\n",
       "       [1, 1, 1, 7, 2, 8],\n",
       "       [1, 1, 1, 6, 7, 1]])"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#水平拼接\n",
    "np.hstack([A,B])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "d8c0cc42-8514-4998-ba1e-49a53c317598",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 1, 1],\n",
       "       [1, 1, 1],\n",
       "       [1, 1, 1],\n",
       "       [0, 0, 7],\n",
       "       [7, 2, 8],\n",
       "       [6, 7, 1]])"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#竖直拼接\n",
    "np.vstack([A,B])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bbb8819e-d673-49d2-b7a4-baad873c2b7c",
   "metadata": {},
   "source": [
    "## 最大值、最小值、平均值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "27618972-ed17-43e5-8756-94413da18fe9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "B.max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "a5f70654-63df-4f8e-9a84-d930238fed36",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "B.min()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "ff0eaffe-4384-44c2-b0da-9774061ec68a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4.222222222222222"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "B.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "418405d8-9cae-45f9-b8ed-ea2bdf92e920",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(8, 0)"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "B.max(),B.min()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "bd64bb7c-dc5f-47f5-9357-6e21b105b1c7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(8, 0, 4.222222222222222)"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "B.max(),B.min(),B.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "5005a4a0-a7c6-42ff-b130-222c4cf23624",
   "metadata": {},
   "outputs": [],
   "source": [
    "#shift+tab"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dce93491-e88d-483c-ba80-1f5615373cc3",
   "metadata": {},
   "source": [
    "## 数学运算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "55a472c3-9333-429e-95a2-e010302731cf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 1, 8],\n",
       "       [8, 3, 9],\n",
       "       [7, 8, 2]])"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A + B"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "87f3186f-b45e-4d91-bd0f-d33e0c9f5215",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1,  1, -6],\n",
       "       [-6, -1, -7],\n",
       "       [-5, -6,  0]])"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A - B "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "066ee31d-769c-456c-b8bf-d03ab34ae19e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 1, 1],\n",
       "       [1, 1, 1],\n",
       "       [1, 1, 1]], dtype=uint8)"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#幂指数\n",
    "np.power(A,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "04a05e7e-1965-4480-8ea8-4285b441bc3f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  0, 49],\n",
       "       [49,  4, 64],\n",
       "       [36, 49,  1]], dtype=int32)"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.power(B,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "d4121456-2bb3-4b29-b91f-ae6b437815ad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.        , 0.        , 2.64575131],\n",
       "       [2.64575131, 1.41421356, 2.82842712],\n",
       "       [2.44948974, 2.64575131, 1.        ]])"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#算数平方根\n",
    "np.sqrt(B)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "be4f2ce2-b3ea-4f28-b130-6945d8e267c1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.        , 0.        , 2.07944154],\n",
       "       [2.07944154, 1.09861229, 2.19722458],\n",
       "       [1.94591015, 2.07944154, 0.69314718]])"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.log(B+1) #e"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "2a89bfbd-9952-4856-b3b3-5548c625534b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.        , 0.        , 3.        ],\n",
       "       [3.        , 1.5849625 , 3.169925  ],\n",
       "       [2.80735492, 3.        , 1.        ]])"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.log2(B+1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "24b7aa35-8bf3-4194-9258-cfde96f8a053",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 3])"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "5cb54891-7b95-4297-bedf-9b0bd57c1b0f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 1, 1],\n",
       "       [1, 1, 1],\n",
       "       [1, 1, 1]], dtype=uint8)"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "a7d2e0ea-7eee-42e1-ad75-d999a4f79b9f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3],\n",
       "       [1, 2, 3],\n",
       "       [1, 2, 3]])"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A * x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "522a396c-90ac-4565-9fc0-32f1e1eb8a6b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([6, 6, 6])"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#矩阵乘法\n",
    "A @ x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "7bcab1ab-2c41-4abf-8624-1135046c9941",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([6, 6, 6])"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A.dot(x)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "491565d5-e03d-4dea-a398-9e93d6be50cc",
   "metadata": {},
   "source": [
    "## 元素获取"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "8bf731b3-3874-49ac-8fce-c3bd8424f2cd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 0, 7],\n",
       "       [7, 2, 8],\n",
       "       [6, 7, 1]])"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "B"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "37d86f43-d44b-44b2-8cb2-29c13e26cc8b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 0, 7])"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#取行\n",
    "B[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "ce001082-2f59-4bbc-8e29-e6ba649edfc7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 0, 7])"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "B[0,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "736951dc-3d04-46e1-a37e-a170d3e2c82f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 7, 6])"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#取列\n",
    "B[:,0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "69b14c7c-6d89-401d-849a-cadbd437717c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[2, 8],\n",
       "       [7, 1]])"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "B[1:,1:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "1115dee0-5f8b-4085-98c2-c2f5133d9c1d",
   "metadata": {},
   "outputs": [],
   "source": [
    "B[0,0] = 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "0dcac26f-d463-4bc5-b776-0969ca08fa8c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[10,  0,  7],\n",
       "       [ 7,  2,  8],\n",
       "       [ 6,  7,  1]])"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "B"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "da8bd5a5-2a21-4ce8-8924-ffb9c8787b0e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 1, 1],\n",
       "       [7, 2, 8],\n",
       "       [6, 7, 1]])"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "B[0,:] = np.array([1,1,1])\n",
    "B"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
